package org.sauceggplant.item.man.service.impl;

import org.sauceggplant.item.man.data.h2.H2ConnectionUtil;
import org.sauceggplant.item.man.data.mysql.MySqlConnectionUtil;
import org.sauceggplant.item.man.service.DbConnectionService;

import java.sql.Connection;

public class DbConnectionServiceImpl implements DbConnectionService {

    private MySqlConnectionUtil mySqlConnectionUtil;

    private H2ConnectionUtil h2ConnectionUtil;

    public static final String MYSQL_TYPE = "mysql";

    public static final String H2_TYPE = "h2";

    public DbConnectionServiceImpl(){
        mySqlConnectionUtil = new MySqlConnectionUtil();
        h2ConnectionUtil = new H2ConnectionUtil();
    }

    @Override
    public Connection getConnection(String type) {
        if (MYSQL_TYPE.equals(type)) {
            return mySqlConnectionUtil.getConnection();
        }
        return h2ConnectionUtil.getConnection();
    }
}
